library IEEE;

use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity LogIntUpa is
Port ( --clk : in STD_LOGIC;
UPA : in std_logic_vector (9 downto 0);
mux1 : out std_logic_vector (2 downto 0);
mux2 : out std_logic_vector (2 downto 0);
mux3 : out std_logic_vector (1 downto 0);
operacion : out std_logic_vector (2 downto 0);
reset : out std_logic;
inc : out std_logic;
corrizq : out std_logic;
corrder : out std_logic;    
ena : out std_logic;
Qcorrizq : out std_logic;
Qcorrder : out std_logic);    




end LogIntUpa;
architecture Behavioral of LogIntUpa is
constant a : std_logic_vector(2 downto 0) := "000";
constant b : std_logic_vector(2 downto 0) := "001";
constant c : std_logic_vector(2 downto 0) := "010";
constant d : std_logic_vector(2 downto 0) := "011";
constant e : std_logic_vector(2 downto 0) := "100";

begin

process (UPA)
begin

			if(UPA(3 downto 0)="0000")     --R = A       S=0
				then mux1 <= a;
				mux2 <= e;
				inc <= '0';
				reset <= '0';
			elsif (UPA(3 downto 0)="0001")   -- R= A     S= B
				then mux1 <= a;
				mux2 <= c;
				inc <= '0';
				reset <= '0';
			elsif (UPA(3 downto 0)="0010")    -- r= q    s=0
		    	then mux1 <= e;
				mux2 <= e;
				inc <= '0';
				reset <= '0';
			elsif (UPA(3 downto 0)="0011")    -- R = B   S=0
				then mux1 <= d;
				mux2 <= e;
				inc <= '0';
				reset <= '0';	
			elsif (UPA(3 downto 0)="0100")    -- R =0     S=A
				then mux1 <= b;
				mux2 <= a;
				inc <= '0';
				reset <= '0';	
			elsif (UPA(3 downto 0)="0101")    -- R =D     S=A
				then mux1 <= c;
				mux2 <= a;
				inc <= '0';
				reset <= '0';	
			elsif (UPA(3 downto 0)="0110")    -- R =D     S=Q
				then mux1 <= c;
				mux2 <= d;
				inc <= '0';
				reset <= '0';	
			elsif (UPA(3 downto 0)="0111")    -- R = D    S=0
				then mux1 <= c;
				mux2 <= e;
				inc <= '0';
				reset <= '0';	
			elsif (UPA(3 downto 0)="1000")    -- R = D    S=B
				then mux1 <= c;
				mux2 <= c ;
				inc <= '0';
				reset <= '0';	
			elsif (UPA(3 downto 0)="1001")    -- R = Q    S=B
				then mux1 <= e;
				mux2 <= c ;
				inc <= '0';
				reset <= '0';		
			elsif (UPA(3 downto 0)="1010")    -- R = 0    S=0
				then mux1 <= b;
				mux2 <= e ;
				inc <= '0';
				reset <= '1';		
			elsif (UPA(3 downto 0)="1011")    -- R = 0    S=0
				then mux1 <= b;
				mux2 <= e ;
				inc <= '1';
				reset <= '0';		
			elsif (UPA(3 downto 0)="1100")    -- R = Q    S=A
				then mux1 <= e ;
				mux2 <= a ;
				inc <= '0';
				reset <= '0';		
			end if;

			if(UPA(6 downto 4)="000")     -- suma
				then operacion <= "000";
			elsif (UPA(6 downto 4)="001")   -- resta  S-R
				then operacion <= "001";
			elsif (UPA(6 downto 4)="010")   -- resta  R-S
				then operacion <= "010";
			elsif (UPA(6 downto 4)="011")   -- OR
				then operacion <= "011";
			elsif (UPA(6 downto 4)="100")   -- AND
				then operacion <= "100";
			elsif (UPA(6 downto 4)="101")   -- COMPLEMENTO R AND S
				then operacion <= "101";
			elsif (UPA(6 downto 4)="110")   -- OR EXCLUSIVO
				then operacion <= "110";
			elsif (UPA(6 downto 4)="111")   -- NOR EXCLUSIVO 
				then operacion <= "111";
			end if;		

			if(UPA(9 downto 7)="000")     -- 
				then mux3 <= "01";
					  corrizq <= '0';
					  corrder <= '0';
					  ena <= '1';
					  Qcorrizq <= '0';
					  Qcorrder <= '0';
			elsif (UPA(9 downto 7)="001")   --
				then mux3 <= "01";
					  corrizq <= '0';
					  corrder <= '0';
					  ena <= '0';
					  Qcorrizq <= '0';
					  Qcorrder <= '0'; 
			elsif (UPA(9 downto 7)="010")   -- 
				then mux3 <= "00" ;
				     corrizq <= '0';
					  corrder <= '0';
					  ena <= '0';
					  Qcorrizq <= '0';
					  Qcorrder <= '0'; 
			elsif (UPA(9 downto 7)="011")   -- 
				then mux3 <= "10" ;
				     corrizq <= '0';
					  corrder <= '0';
					  ena <= '0';
					  Qcorrizq <= '0';
					  Qcorrder <= '0'; 
			elsif (UPA(9 downto 7)="100")   -- YUPA/2 CORRIMIENTO A LA DERECHA
				then mux3 <= "10" ;
				     corrizq <= '0';
					  corrder <= '1';
					  ena <= '0';
					  Qcorrizq <= '0';
					  Qcorrder <= '0'; 
			elsif (UPA(9 downto 7)="101")   -- Q/2 CORRIMIENTO A LA DERECHA
				then mux3 <= "10" ;
				     corrizq <= '0';
					  corrder <= '0';
					  ena <= '1';
					  Qcorrizq <= '0';
					  Qcorrder <= '1'; 
			elsif (UPA(9 downto 7)="110")   -- 2YUPA CORRIMIENTO A LA IZQ
				then mux3 <= "10" ;
				     corrizq <= '1';
					  corrder <= '0';
					  ena <= '0';
					  Qcorrizq <= '0';
					  Qcorrder <= '0'; 
	
			elsif (UPA(9 downto 7)="111")   -- 2Q CORRIMIENTO A LA IZQ
				then mux3 <= "10" ;
				     corrizq <= '0';
					  corrder <= '0';
					  ena <= '1';
					  Qcorrizq <= '1';
					  Qcorrder <= '0'; 
	
			end if;		


end process;
end Behavioral;